<template>
	<view class="index-root">
		<!-- {{ errorMsg }} -->
		<u-loading-page :loading="loading"></u-loading-page>
	</view>
</template>

<script>
	import {
		initUserInfo
	} from "@/service/user";
	import {
		getToken
	} from "@/util/means/request";
	import {
		indexPage,
		loginPage,
		minePage
	} from "@/util/publicConfig";

	export default {
		name: "index",
		data() {
			return {
				loading: false,
				errorMsg: '刚开始'
			}
		},
		onLoad() {
			this.checkLogin()
		},
		methods: {
			async checkLogin() {
				this.errorMsg = '去获取token了'
				const token = getToken();
				this.errorMsg = 'token获取成功了'
				let subPagePath = loginPage
				if (token != null && token !== '') {
					this.errorMsg = '要去初始化用户信息了'
					await initUserInfo()
					this.errorMsg = '用户信息初始化成功了'
					subPagePath = indexPage
				}
				this.errorMsg = `要跳转页面了 页面地址是:${subPagePath}`
				try {
					uni.redirectTo({
						url: subPagePath
					});
				} catch (e) {
					this.errorMsg = `这是错误信息 ${e}`
				}
			}
		},
	}
</script>

<style scoped lang="scss">
	.index-root {
		background: pink;

		.test {
			font-size: 30rpx;
			color: #f00;
		}
	}
</style>
